package com.server.executor.factory;

import org.jetbrains.annotations.NotNull;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Description: This is a sample class.
 * @Author: Simon
 */
public final class NamingThreadFactory implements ThreadFactory {

    private final AtomicInteger threadNum=new AtomicInteger();
//    private final ThreadFactory delegate;
    private final String threadName;

    public NamingThreadFactory(String threadName) {
//        this.delegate = delegate;
        this.threadName = threadName;
    }

    @Override
    public Thread newThread(@NotNull Runnable r) {
        Thread thread = new Thread(r);
        thread.setName(threadName + " [#" + threadNum.incrementAndGet() + "]");
        return thread;
    }
}
